package fr.p10.miage.gestionabsence.form;

import fr.p10.miage.gestionabsence.model.EmailValidateur;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Sofian Seid
 */
public class LoginActionForm extends org.apache.struts.action.ActionForm {
    
   private String login;
   private String password;

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    } 

    /**
     *
     */
    public LoginActionForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    
    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
             
        ActionErrors errors = new ActionErrors();
        EmailValidateur emailValidateur= new EmailValidateur();
        boolean valid = emailValidateur.validate(this.login);
        
        if (this.login == null || this.login.length() < 1 || valid == false) {
            errors.add("login", new ActionMessage("errors.required", " L'identifiant"));
        }
        else if (this.password == null || this.password.length() < 1) {
            errors.add("password", new ActionMessage("errors.required", " Le mot de passe"));
        }        

        return errors;
    }
}